package com.xqy.wexmini.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "邮件发送")
@RestController
@RequestMapping("/mail")
public class MailController {

    //定义邮件发送器
    @Autowired
    private JavaMailSender mailSender;

    /**
     * @param
     * @param subject 主题
     * @param content 内容
     * @Value注解读取配置文件中同名的配置值
     */
    @ApiOperation("发送")
    @PostMapping("/to")
    public void sendSimpleMail(String subject, String content) {
        //发送到
        String to="2080138418@qq.com";
        //创建一个简单文本邮件的对象
        SimpleMailMessage message = new SimpleMailMessage();
        //赋予相应的内容
        message.setTo(to);
        message.setSubject(subject);
        message.setText(content);
        message.setFrom("2080138418@qq.com");
        //将邮件对象赋予邮件发送器
        mailSender.send(message);
    }
}
